//
//  RegistViewController.m
//  happyHealthyWalk
//
//  Created by newhuidong on 16/2/20.
//  Copyright © 2016年 HuiDong. All rights reserved.
//

#import "RegistViewController.h"
#import "Header.h"
#import "UIBarButtonItem+Extensions.h"
#import "LGSelectButtonView.h"
#import "RegistTableViewCell.h"
@interface RegistViewController ()<LGSelectButtonViewDelegate,UITableViewDataSource,UITableViewDelegate>{
    
    LGSelectButtonView * _view;
    
}
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *codeTF;

@property (weak, nonatomic) IBOutlet UITextField *pswTF;
@property (weak, nonatomic) IBOutlet UIButton *registerButton;
@property (weak, nonatomic) IBOutlet UIButton *getCode;

@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIView *topBgView;
@property (weak, nonatomic) IBOutlet UILabel *change_label;
@property (weak, nonatomic) IBOutlet UILabel *seound_changelabel;
@property (weak, nonatomic) IBOutlet UITextField *phoneNum_tf;
@property (weak, nonatomic) IBOutlet UITextField *confirm_phonetf;
@property(nonatomic, copy) NSString *oUserPhoneNum;
@property(assign, nonatomic) NSInteger timeCount;
@property(strong, nonatomic) NSTimer *timer;
//验证码
@property(copy, nonatomic) NSString *smsId;

@end

@implementation RegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor=[UIColor whiteColor];
    
    self.title=@"注册";
    self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor]};
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor=GreenColor;
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage=[UIImage new];
    self.navigationController.navigationBar.translucent=NO;
    [self setupUI];
    
    LGSelectButtonView * view=[[LGSelectButtonView alloc]initWithFrame:CGRectMake(90, 5, ScreenW-90, 120)];
    view.tableViewTextLableArray=@[@"患者用户",@"患者家属",@"康复爱心人士"];
    view.buttonHeight=40;
    view.backgroundColor=[UIColor groupTableViewBackgroundColor];
    
    view.buttonDefaultTitle=@"-请选择-";
    view.buttonTitleFontName=@"HelveticaNeue-Thin";
    view.buttonTitleFontSize = 15;
    view.tableViewRowHeight = 30;
    view.backColorAlpha = 0.6;
    [view closeTableView];
    view.delegate = self;
    view.layer.cornerRadius = 5;
    view.layer.masksToBounds = YES;
    _view=view;
    [self.topBgView addSubview:_view];
    
    
    LGSelectButtonView * view1=[[LGSelectButtonView alloc]initWithFrame:CGRectMake(90, 55, ScreenW-90, 120)];
    view1.tableViewTextLableArray=@[@"胃部疾病",@"肠道疾病"];
    view1.buttonHeight=40;
    view1.backgroundColor=[UIColor groupTableViewBackgroundColor];
    
    view1.buttonDefaultTitle=@"-请选择-";
    
    view1.buttonTitleFontName=@"HelveticaNeue-Thin";
    view1.buttonTitleFontSize = 15;
    view1.tableViewRowHeight = 30;
    view1.backColorAlpha = 0.6;
    [view1 closeTableView];
    view1.delegate = self;
    view1.layer.cornerRadius = 5;
    view1.layer.masksToBounds = YES;
    _view=view1;
    [self.topBgView addSubview:_view];

    
    [self.topBgView bringSubviewToFront:view];
    

    
}

-(void)didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        
        self.seound_changelabel.text=@"医院名称:";
        self.change_label.hidden=YES;
        
    }else if  (indexPath.row==1) {
        self.change_label.hidden=NO;
        self.phoneNum_tf.hidden=NO;
        
        self.change_label.text=@"匹配患者手机号:";
        self.seound_changelabel.text=@"确认患者手机号:";
        self.change_label.adjustsFontSizeToFitWidth=YES;
        self.seound_changelabel.adjustsFontSizeToFitWidth=YES;
        
        
    }else{
        
        
        
        
        
    }
    
}

-(void)setupUI{
    
    
    self.phoneTF.keyboardType=UIKeyboardTypeNumberPad;
    self.codeTF.keyboardType=UIKeyboardTypeNumberPad;
    self.registerButton.layer.cornerRadius=5;
    
    
}
- (IBAction)agreeRual:(id)sender {
    UIButton * button=sender;
    
    button.selected=!button.selected;
    
    
    
}
- (IBAction)getCode:(id)sender {
    

    if ([self.phoneTF.text isEqualToString:@""]&&self.phoneTF.text.length<11) {
        
        UIAlertController * alert=[UIAlertController alertControllerWithTitle:nil message:@"请输入手机号" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:nil];
        
        [alert dismissViewControllerAnimated:YES completion:nil];
        
        
        
        return;
        
    }
    _oUserPhoneNum=self.phoneTF.text;
    
    self.timeCount=30;
    
    
    
    self.timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(reduceTime:) userInfo:sender repeats:YES];
    
}



-(void)reduceTime:(NSTimer *)codeTimer{
    
    self.timeCount--;
    if (self.timeCount ==0) {
        
        [self.getCode setTitle:@"重新获取" forState:0];
        [self.getCode setTitleColor:[UIColor colorWithRed:248/255.0f green:144/255.0f blue:34/255.0f alpha:1] forState:UIControlStateNormal];
        UIButton * info =codeTimer.userInfo;
        info.enabled=YES;
        self.getCode.userInteractionEnabled=YES;
        [self.timer invalidate];
        
    }else{
        
        NSString * str=[NSString stringWithFormat:@"%lu",(long)self.timeCount];
        [self.getCode setTitle:str forState:UIControlStateNormal];
        self.getCode.userInteractionEnabled=YES;
        
        
        
    }
}
-(void)viewWillAppear:(BOOL)animated{
    
    
    
}
//键盘下落
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
    
}
@end
